package cn.northsea.listenner;


import cn.northsea.mapper.UserMapper;
import cn.northsea.pojo.User;
import com.alibaba.excel.context.AnalysisContext;

import com.alibaba.excel.event.AnalysisEventListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
public class UserLinstenner extends AnalysisEventListener<User> {
    @Autowired
    private UserMapper userMapper;
    private static List<User> list=new ArrayList<>();
    public static List<User> getList(){
        return list;
    }
    @Override
    public void invoke(User user, AnalysisContext analysisContext) {
        User user2=userMapper.findUserById(user.getUserId());
        if (user2!=null){
                list.add(user2);
        }else {
            userMapper.addUser(user);
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
